-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix form checkValidity(), remove vnode.dom === .activeElement from isFormAttribute() and setAttr() #2257
Conversation
render/render.js
Outdated
@@ -747,7 +747,7 @@ module.exports = function($window) { | |||
} | |||
} | |||
function isFormAttribute(vnode, attr) { | |||
return attr === "value" || attr === "checked" || attr === "selectedIndex" || attr === "selected" && vnode.dom === $doc.activeElement || vnode.tag === "option" && vnode.dom.parentNode === $doc.activeElement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure removing this activeElement
check makes sense? It seems to be associated to changing the selected
attr. Do we know what this check was trying to achieve? I don't think it's related to #2256
Here is the old condition with parentheses to clarify it.
return (
attr === 'value' ||
attr === 'checked' ||
attr === 'selectedIndex' ||
(attr === 'selected' && vnode.dom === $doc.activeElement) ||
(vnode.tag === 'option' && vnode.dom.parentNode === $doc.activeElement)
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nit below, but you also need to write some tests so we know the fix actually works.
render/render.js
Outdated
@@ -747,7 +747,7 @@ module.exports = function($window) { | |||
} | |||
} | |||
function isFormAttribute(vnode, attr) { | |||
return attr === "value" || attr === "checked" || attr === "selectedIndex" || attr === "selected" && vnode.dom === $doc.activeElement || vnode.tag === "option" && vnode.dom.parentNode === $doc.activeElement | |||
return attr === "value" || attr === "checked" || attr === "selectedIndex" || attr === "selected" || vnode.tag === "option" && vnode.dom.parentNode === $doc.activeElement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please revert this for now and only fix the one issue with input.value
? The comment in the bug regarding this was me noting I wanted to investigate (since it appeared similar in use), not that I actively wanted to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
This is certainly wrong, but I'm having a heck of a time wrapping my head around ospec. o("checkValidity", function() {
var value = "";
var spy = o.spy()
var context = {
handler: withAttr("value", spy)
}
var form = {tag: "form", attrs: {
novalidate: true,
onsubmit: function(e) {
e.preventDefault();
}
}, children: [
{tag: "input", attrs: {value: value, oninput: withAttr("value", function(v) { value = v; })}},
{tag: "button", attrs: {type: "submit"}}
]}
render(root, [form])
context.handler({currentTarget: {value: "abcd"}})
// submit form
o(form.dom.checkValidity()).equals(false)
context.handler({currentTarget: {value: "abc"}})
// submit form
o(form.dom.checkValidity()).equals(false)
}) |
|
@isiahmeadows I'm including the Fork in my project ATM. |
@isiahmeadows
I don't think this is fair, since this bugfix merely reverts bugfix code which wasn't tested for anyway. Even if that weren't the case, extending Mithril's DOM mocks to emulate W3C form validation — let alone to the point that we can reasonably account subtle implementation details like this one — is a hiding to nothing. I think having the back link to the test cases provided in the original issue is a good enough validation. |
Could you find the commit that added it, so we can find the surrounding context?
Or we could just invoke
I don't like adding bug fixes without tests, just in principle. I'd rather not us be back here a second time because of an erroneous "bug fix" that breaks it again - it's happened before already IIRC. |
Already fix in |
Remove
vnode.dom === $doc.activeElement
fromisFormAttribute()
, andsetAttribute()
to fixvalidityCheck()
, #2256Description
When using
m.withAttr()
to maintain aninput
value
, the form'scheckValidity()
method sometimes returns true when form fields are not valid. This happens on the second and subsequent submissions.Motivation and Context
This fixes
checkValidation()
.#2256
How Has This Been Tested?
Here's a version of the modified code on flems.io
Types of changes
Checklist:
docs/change-log.md